from django.db import models

# Create your models here.

#后台任务表
class Task(models.Model):
    class Meta:
        db_table = 'task'
    id = models.IntegerField(verbose_name='任务id',primary_key=True,null=False)
    src_id = models.IntegerField(verbose_name='数据源id',null=False)

#数据源表
class DataSrc(models.Model):
    class Meta:
        db_table = 'datasrc'
        unique_together = [['json']]
    type = models.CharField(verbose_name='数据源类型',max_length=5,null=False)
    name = models.CharField(verbose_name='数据源名称',max_length=15,null=False)
    status = models.BooleanField(verbose_name='同步状态',default=False)
    json = models.CharField(verbose_name='json格式数据源参数',max_length=200,null=False)     

#平台用户表
class Users(models.Model):
    class Meta:
        db_table = 'users'
    username = models.CharField(primary_key=True,max_length=16,null=False)
    password = models.CharField(max_length=16,null=False)
    share = models.BooleanField(verbose_name='共享模块使用权限',default=False)
    admin = models.BooleanField(verbose_name='管理员账号标识',default=False)
    id = models.CharField(verbose_name='共享模块实名',max_length=18,null=True)
    name = models.CharField(verbose_name='姓名',max_length=10,null=True)

#客户信息表
class Client(models.Model):
    class Meta:
        db_table = 'client'
        unique_together = [['clientid', 'user']]
    name = models.CharField(verbose_name='客户名称',max_length=12,null=False)
    clientid = models.CharField(verbose_name='客户编号',max_length=18,null=False)
    tel = models.CharField(verbose_name='手机号',max_length=11,null=False)
    addr = models.CharField(verbose_name='省市区',max_length=32,null=False)
    user = models.ForeignKey(to='Users',to_field='username',on_delete=models.CASCADE)#记级联用户表

#物流信息表
class TradeInfo(models.Model):
    class Meta:
        db_table = 'tradeinfo'
        unique_together = [['tradeid', 'user']]
    tradeid = models.CharField(verbose_name='提单号',max_length=15,null=False)
    client = models.CharField(verbose_name='货主名称',max_length=10,null=False)
    clientid = models.CharField(verbose_name='货主代码',max_length=18,null=False)
    company = models.CharField(verbose_name='物流公司',max_length=20,null=False)
    container = models.CharField(verbose_name='集装箱箱号',max_length=50,null=False)
    goods = models.CharField(verbose_name='货物名称',max_length=10,null=False)
    weight = models.IntegerField(verbose_name='货重(吨)',default=0)
    user = models.ForeignKey(to='Users',to_field='username',on_delete=models.CASCADE)#记级联用户表

#物流公司表
class TradeCompany(models.Model):
    class Meta:
        db_table = 'tradecompany'
        unique_together = [['clientid', 'user']]
    company = models.CharField(verbose_name='公司名称',max_length=20,null=False)
    clientid = models.CharField(verbose_name='客户编号',max_length=20,null=False)
    admin = models.CharField(verbose_name='联系人',max_length=10,null=False)
    tel = models.CharField(verbose_name='电话',max_length=11,null=False)
    area = models.CharField(verbose_name='省市区',max_length=20,null=False)
    user = models.ForeignKey(to='Users',to_field='username',on_delete=models.CASCADE)#记级联用户表

#装货表表
class Ship(models.Model):
    class Meta:
        db_table = 'ship'
        unique_together = [['sid', 'user']]
    company = models.CharField(verbose_name='船公司',max_length=10,null=False)
    shipname = models.CharField(verbose_name='船名称',max_length=20,null=False)
    btime = models.DateField(verbose_name='作业开始时间',null=False)
    etime = models.DateField(verbose_name='作业结束时间',null=False)
    gotime = models.DateField(verbose_name='始发时间',null=False)
    artime = models.DateField(verbose_name='到达时间',null=False)
    harbor = models.CharField(verbose_name='作业港口',max_length=10,null=False)
    sid = models.CharField(verbose_name='提单号',max_length=15,null=False)
    con_id = models.CharField(verbose_name='集装箱箱号',max_length=50,null=False)
    size = models.IntegerField(verbose_name='集装箱尺寸',default=0,null=False)
    source = models.CharField(verbose_name='启运地',max_length=10,null=False)
    destination = models.CharField(verbose_name='目的地',max_length=10,null=False)
    user = models.ForeignKey(to='Users',to_field='username',on_delete=models.CASCADE)#记级联用户表

#卸货表
class Unship(models.Model):
    class Meta:
        db_table = 'unship'
        unique_together = [['sid', 'user']]
    company = models.CharField(verbose_name='船公司',max_length=10,null=False)
    shipname = models.CharField(verbose_name='船名称',max_length=20,null=False)
    btime = models.DateField(verbose_name='作业开始时间',null=False)
    etime = models.DateField(verbose_name='作业结束时间',null=False)
    gotime = models.DateField(verbose_name='始发时间',null=False)
    artime = models.DateField(verbose_name='到达时间',null=False)
    harbor = models.CharField(verbose_name='作业港口',max_length=10,null=False)
    sid = models.CharField(verbose_name='提单号',max_length=15,null=False)
    con_id = models.CharField(verbose_name='集装箱箱号',max_length=50,null=False)
    size = models.IntegerField(verbose_name='集装箱尺寸',default=0,null=False)
    source = models.CharField(verbose_name='启运地',max_length=10,null=False)
    destination = models.CharField(verbose_name='目的地',max_length=10,null=False)
    user = models.ForeignKey(to='Users',to_field='username',on_delete=models.CASCADE)#记级联用户表   

#集装箱动态表
class Container(models.Model):
    class Meta:
        db_table = "container"
        unique_together = [['sid', 'user','op','con_id','harbor']]
    harbor = models.CharField(verbose_name='堆存港口',max_length=10,null=False)
    con_id = models.CharField(verbose_name='集装箱箱号',max_length=15,null=False)
    size = models.IntegerField(verbose_name='集装箱尺寸',default=0,null=False)
    sid = models.CharField(verbose_name='提单号',max_length=15,null=False)
    store = models.CharField(verbose_name='堆场位置',max_length=10,null=False)
    op = models.CharField(verbose_name='操作',max_length=5,null=False)
    opdata = models.DateField(verbose_name='操作日期',null=False)
    user = models.ForeignKey(to='Users',to_field='username',on_delete=models.CASCADE)#记级联用户表   
